package org.yaac.shared.property;

import static com.google.common.collect.Lists.newArrayList;

import java.util.List;

import org.yaac.shared.egql.ResultCell;
import org.yaac.shared.egql.ResultCell.ResultCellFactory;



/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
public class NullPropertyInfo extends PropertyInfo {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private static final String NULL = "NULL";
	
	@Override
	public String asHtml() {
		return NULL;
	}
	
	@Override
	public int compareTo(PropertyInfo o) {
		if (o instanceof NullPropertyInfo) {
			return 0;
		} else {
			// null value is the smallest value
			// refer to http://code.google.com/appengine/docs/java/datastore/entities.html
			return -1;	
		}
	}

	@Override
	public ResultCell populateResultCell(ResultCellFactory factory) {
		ResultCell cell = super.populateResultCell(factory);
		cell.setType(PropertyType.NULL);
		cell.setParent(null);
		cell.setChildren(null);
		cell.setPayload(null);
		return cell;
	}

	@Override
	public int hashCode() {
		int result = 1;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return "NullPropertyInfo []";
	}

	@Override
	public String asExpression(FilePlaceHolder placeHolder) {
		return "null()";
	}
	
	@Override
	public List<String> downloadPaths() {
		return newArrayList();
	}
}
